package chapter05

/**
  * create by undeRdoG on  2021-05-30  20:47
  * 凡心所向，素履以往，生如逆旅，一苇以航。
  */
object Test07_Practice_CollectionOperation {

  def main(args: Array[String]): Unit = {
    //  对数组进行处理   将操作抽象出来   处理完毕之后的结果返回新的数组

    val arr: Array[Int] = Array(12,45,75,98)

    def arrayOperation(array: Array[Int],op: Int => Int): Array[Int] = {
      for (elem <- array) yield op(elem)
    }

    // 定义一个  + 1 操作
    def addOne(ele: Int): Int = {
      ele + 1
    }

    val res: Array[Int] = arrayOperation(arr,addOne)
    println(res.mkString(","))


    // 传入匿名函数，数组中的每个元素翻倍
    //val res1: Array[Int] = arrayOperation(res, ele => ele * 2)
    val res1: Array[Int] = arrayOperation(res, _ * 2)

    println(res1.mkString(","))
  }

}
